home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Archive / QuickTime / QuickTime VR / Make QTVR Object / Main.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  7.6 KB  |  326 lines  |  [TEXT/KAHL]

  1. //
  2. //         This is sample code which will make QTVR object movies from Linear QuickTime movies.
  3. //
  4. //        © 1991-1996 Apple Computer, Inc.  All rights reserved.
  5. //
  6.  
  7.  
  8. #include    "MakeQTVRObject.h"
  9.  
  10. Boolean                            gDone;
  11. AEAddressDesc                    pSelfAddress;            // A self-addressed address descriptor record
  12. ProcessSerialNumber                pSelfPSN;                // This application's psn
  13. AEDesc                            pnilDesc;    
  14. PrefInfo                        gPrefInf;
  15. FSSpec                             gPrefSpec;
  16.  
  17. void    main()
  18. {
  19.     gDone = false;
  20.     ToolBoxInit();
  21.     Splash();
  22.     MainLoop();
  23.     Cleanup();
  24.     ExitToShell();
  25. }
  26.  
  27. /***** Show splash Dialog *****/
  28. void    Splash()
  29. {
  30.  
  31.     DialogPtr    myDlg;
  32.     unsigned long    startSecs,currentSecs;
  33.     
  34.     myDlg = GetNewDialog( kSplashDLOG, 0, (WindowPtr) -1);
  35.     DrawDialog (myDlg);
  36.     GetDateTime (&startSecs);
  37.     GetDateTime (¤tSecs);
  38.     
  39.     while (currentSecs - startSecs < 2)    
  40.         GetDateTime (¤tSecs);
  41.         
  42.     DisposDialog( myDlg);
  43.  
  44. }
  45. /*********Toolbox init*************/
  46. void    ToolBoxInit()
  47. {    
  48.     InitGraf(&qd.thePort);
  49.     InitFonts();
  50.     InitWindows();
  51.     InitMenus();
  52.     InitDialogs(nil);
  53.     InitCursor();
  54.     TEInit();
  55.     MaxApplZone();
  56.     AEInit();
  57.     
  58.     MenuBarInit();
  59.     
  60.     if(RetrievePrefs())
  61.         {
  62.         gDone = true;
  63.         return;
  64.         }
  65.     if(EnterMovies())
  66.         {
  67.         UserMessage("\pCould not initialize QuickTime.");
  68.         gDone = true;
  69.         return;
  70.         }    
  71.     if(!RegisterComponentResourceFile(CurResFile(), 0))
  72.         {
  73.         UserMessage("\pCould not find the QuickTime VR components.");
  74.         gDone = true;
  75.         return;
  76.         }
  77. }
  78.  
  79.  
  80.  
  81. /*********Initialize AppleEvents*************/
  82. void    AEInit()
  83. {
  84.     OSErr  err;
  85.     
  86.     // Set up the self-addressed descriptor record.
  87.     pSelfPSN.highLongOfPSN = 0;
  88.     pSelfPSN.lowLongOfPSN = kCurrentProcess;        // Use this instead of GetCurrentProcess
  89.     err = AECreateDesc(typeProcessSerialNumber,(Ptr)&pSelfPSN,sizeof(ProcessSerialNumber),&pSelfAddress);
  90.     
  91.     pnilDesc.descriptorType = typeNull;            // Initialize the global nil descriptor record.
  92.     pnilDesc.dataHandle = nil;
  93.     
  94.     RegisterMyEvents() ;                            // and finally register appleEvent handlers
  95.     
  96. }
  97.  
  98.  
  99. Boolean SupportsAEVT(void)
  100. {
  101.     OSErr err;
  102.     long response;
  103.     
  104.     
  105.     err = Gestalt(gestaltAppleEventsAttr,&response);
  106.     if (err!=noErr)
  107.         {
  108.         UserMessage("\pDrag and drop will not work because I cannot find the AppleEvent manager.");
  109.         return false;
  110.         }
  111.         
  112.     return (response && (response << gestaltAppleEventsPresent));
  113. }
  114.  
  115. void RegisterMyEvents(void)
  116. {
  117.     OSErr err;
  118.     
  119.     if (!SupportsAEVT())
  120.         return;
  121.     
  122.     err = AEInstallEventHandler(kCoreEventClass,kAEOpenApplication,NewAEEventHandlerProc(DoOpenApp),0L,false);
  123.     if (err!=noErr)
  124.         return;
  125.                 
  126.     err = AEInstallEventHandler(kCoreEventClass,kAEOpenDocuments,NewAEEventHandlerProc(DoOpenDoc),0L,false);
  127.     if (err!=noErr)
  128.         return;
  129.                 
  130.     err = AEInstallEventHandler(kCoreEventClass,kAEPrintDocuments,NewAEEventHandlerProc(DoPrintDoc),0L,false);
  131.     if (err!=noErr)
  132.         return;
  133.                 
  134.     err = AEInstallEventHandler(kCoreEventClass,kAEQuitApplication,NewAEEventHandlerProc(DoQuitApp),0L,false);
  135.     if (err!=noErr)
  136.         return;            
  137.  
  138.     
  139. }
  140.  
  141.  
  142.  
  143. pascal    OSErr    DoOpenApp(AppleEvent    *theAppleEvent,AppleEvent *reply,long    RefCon)
  144. {
  145.     
  146.     return noErr;
  147. }
  148.  
  149. pascal    OSErr    DoQuitApp(AppleEvent    *theAppleEvent,AppleEvent *reply,long    RefCon)
  150. {
  151.     gDone = true;
  152.     return noErr;
  153. }
  154.  
  155.  
  156. pascal    OSErr    DoOpenDoc(AppleEvent    *theAppleEvent,AppleEvent *reply,long    RefCon)
  157. {
  158.     FSSpec         myFSS;
  159.     AEDescList    docList;
  160.     OSErr        err,
  161.                 ignoreErr;
  162.     long        index,
  163.                 itemsInList;
  164.     Size         actualSize;
  165.     AEKeyword    keywd;
  166.     DescType    returnedType;
  167.  
  168.     
  169.      *reply = *reply;
  170.      RefCon = RefCon;
  171.     err = AEGetParamDesc(theAppleEvent,keyDirectObject,typeAEList,&docList);
  172.     if (err == noErr) {
  173.         
  174.         // see how many descriptor items are in the list
  175.         // this is the number of documents we want to open
  176.         err = AECountItems(&docList,&itemsInList);
  177.  
  178.         // now get each descriptor record from the list
  179.         // coerce the returned data to an FSSpec record, and
  180.         // open the asoociated file
  181.         
  182.         for (index=1; index <= itemsInList && err == noErr; index++) {
  183.             
  184.             err = AEGetNthPtr(    &docList, 
  185.                                 index,
  186.                                 typeFSS,
  187.                                 &keywd,
  188.                                 &returnedType,
  189.                                 (Ptr)&myFSS,
  190.                                 sizeof(myFSS),
  191.                                 &actualSize);
  192.     
  193.             if (err == noErr)    {
  194.             
  195.                 FInfo        fndrInfo ;
  196.                 
  197.                 // we now have a valid FSSpec to reference the file, we need to know 
  198.                 // what type the file is to determine which file open function to call
  199.                 // we can determine this from the finder info for the file
  200.                 
  201.                 err = FSpGetFInfo( &myFSS, &fndrInfo );    
  202.                 
  203.                 // if we got that ok, then we switch on the file  
  204.                 // type (we don't care about the creator type)    
  205.                         
  206.                 if (err == noErr)    {
  207.                     
  208.                     switch( fndrInfo.fdType ) {
  209.                         case 'MooV':
  210.                             {
  211.                             if(!OpenMovie(&myFSS) && gPrefInf.dropMode)
  212.                                 {
  213.                                 TimeValue    posterViewTime,frameDur;
  214.                                 MovieInstance    *theInstance;
  215.                                 FInfo            finderInfo;
  216.                                 
  217.                                 err = HGetFInfo (myFSS.vRefNum, myFSS.parID, myFSS.name, &finderInfo);
  218.                                 if (err != noErr) break;
  219.                                 if(finderInfo.fdCreator == kQTVRPlayerCreatorType) break;
  220.                                     
  221.                                 theInstance = GetMovieInstanceFromWindow(FrontWindow());
  222.                                 GetMovieNextInterestingTime (theInstance->movie, nextTimeMediaSample, 0, nil, 0, 1, nil, &frameDur);
  223.                                 posterViewTime = MCGetCurrentTime (theInstance->movieController, nil);
  224.                                 gPrefInf.objectInfo.frameDuration = (short)frameDur;
  225.                                 ConvertTimeToPanUtil (posterViewTime, 
  226.                                                         gPrefInf.objectInfo.frameDuration,
  227.                                                         gPrefInf.objectInfo.numberOfColumns,
  228.                                                         gPrefInf.objectInfo.numberOfRows,
  229.                                                         gPrefInf.objectInfo.loopSize,
  230.                                                         gPrefInf.objectInfo.startHPan,
  231.                                                         gPrefInf.objectInfo.endHPan,
  232.                                                         gPrefInf.objectInfo.startVPan,
  233.                                                         gPrefInf.objectInfo.endVPan,
  234.                                                         &gPrefInf.objectInfo.initialHPan, 
  235.                                                         &gPrefInf.objectInfo.initialVPan);
  236.                                 SetQTVRObjectFileFormat1x0 (
  237.                                                         theInstance->movie,
  238.                                                         theInstance->movieResFile,
  239.                                                         theInstance->movieResID,
  240.                                                         theInstance->spec,
  241.                                                         posterViewTime,
  242.                                                         &gPrefInf.objectInfo);
  243.                                 CloseMovie(FrontWindow());
  244.                                 }
  245.                             }
  246.                             break ;
  247.                         default:
  248.                             gDone = true;
  249.                             break ;
  250.                     }
  251.                 }
  252.             }
  253.         }
  254.         
  255.         ignoreErr = AEDisposeDesc(&docList);
  256.     }
  257.     if(gPrefInf.dropMode) gDone = true;
  258.     return err ;
  259. }
  260.  
  261. pascal    OSErr    DoPrintDoc(AppleEvent    *theAppleEvent,AppleEvent *reply,long    RefCon)
  262. {
  263.     return noErr;
  264. }
  265.  
  266. /***********MenuBarInit*********/
  267. void    MenuBarInit()
  268. {
  269.  
  270.     SetMenuBar (GetNewMBar (128));
  271.     AddResMenu (GetMHandle (appleID), 'DRVR');
  272.     DrawMenuBar();
  273.     SetupMenus();
  274. }
  275.  
  276. void SetupMenus ()
  277. {
  278.     MenuHandle        mh;
  279.     WindowPtr        whichWindow;
  280.     MovieInstance    *theInstance;
  281.     
  282.     whichWindow = FrontWindow();
  283.     theInstance = GetMovieInstanceFromWindow(whichWindow);
  284.     
  285.     // Default File menu setup
  286.     mh = GetMHandle (fileID);
  287.     EnableItem (mh, iOpen);
  288.     EnDisItem  (mh, iClose, (whichWindow != nil));
  289.     EnableItem (mh, iDrop);
  290.     if(gPrefInf.dropMode)     SetItemMark (mh, iDrop, checkMark);
  291.     else                    SetItemMark (mh, iDrop, noMark);
  292.     EnableItem (mh, iSetPrefs);
  293.     EnableItem (mh, iQuit);
  294.     
  295.     // Default Edit menu setup
  296.     mh = GetMHandle (editID);
  297.     DisableItem (mh, iCopy);    // Don't allow editing of Nav Movie.
  298.     DisableItem (mh, iUndo);
  299.     DisableItem (mh, iCut);
  300.     DisableItem (mh, iPaste);
  301.     DisableItem (mh, iClear);
  302.  
  303.     EnDisItem (mh, iMakeObject,  (whichWindow != 0)  && theInstance);
  304.     EnDisItem (mh, iDeleteObject, (whichWindow != 0) && theInstance && theInstance->isObjectMovie);
  305.     EnDisItem (mh, iSetPoster,     (whichWindow != 0) && theInstance && theInstance->isObjectMovie);
  306.     EnDisItem (mh, iShowPoster,   (whichWindow != 0) && theInstance && theInstance->isObjectMovie);
  307. }
  308.  
  309.  
  310. /***** Cleanup *****/
  311. void    Cleanup()
  312. {
  313.     WindowPtr    currWindow;
  314.     
  315.     ExitMovies();
  316.     
  317.     currWindow = FrontWindow();
  318.     while(currWindow)
  319.         {
  320.         CloseMovie(currWindow);
  321.         currWindow = FrontWindow();
  322.         }
  323. }
  324.  
  325.  
  326.